import Icon from '@/components/Icon';
import { useAppSelector } from '@/store';
import { ArticleDetailType } from '@/store/redurce/article';
import { Popup } from 'antd-mobile';
import { useState } from 'react';
import CommentInput from '../CommentInput';
import styles from './index.module.scss';

type CommentFooterProps = {
  // 标记为可选属性
  articleData?: ArticleDetailType;
  // normal 普通评论
  // reply 回复评论
  type?: 'normal' | 'reply';
  onClick?: () => void;
  onShare?: () => void;
};
export default function CommentFooter({
  type = 'normal',
  articleData = {} as ArticleDetailType,
  onClick,
  onShare,
}: CommentFooterProps) {
  const [visible, setVisible] = useState(false);
  const { originComment } = useAppSelector((state) => state.comments);
  return (
    <div className={styles.root}>
      <div className="comment-footer">
        <div className="input-btn" onClick={() => setVisible(true)}>
          <Icon type="iconbianji" />
          <span>去评论</span>
        </div>

        {type === 'normal' && (
          <>
            <div className="action-item" onClick={onClick}>
              <Icon type="iconbtn_comment" />
              <p>评论</p>
              <span className="bage">{articleData.comm_count}</span>
            </div>
            {/* 'iconbtn_like2' */}
            <div className="action-item">
              <Icon
                type={
                  articleData.attitude === 1
                    ? 'iconbtn_like_sel'
                    : 'iconbtn_like2'
                }
              />
              <p>点赞</p>
            </div>
          </>
        )}
        <div className="action-item">
          {/* 'iconbtn_collect' */}
          <Icon
            type={
              articleData.is_collected
                ? 'iconbtn_collect_sel'
                : 'iconbtn_collect'
            }
          />
          <p>收藏</p>
        </div>
        <div className="action-item" onClick={onShare}>
          <Icon type="iconbtn_share" />
          <p>分享</p>
        </div>
      </div>
      {/* 2. 在Footer中使用弹出层组件*/}
      <Popup destroyOnClose visible={visible} bodyStyle={{ height: '100vh' }}>
        {/* 4. 父传子技术 */}
        <CommentInput
          name={originComment.aut_name}
          onBack={() => setVisible(false)}
        />
      </Popup>
    </div>
  );
}
